package com.hxy.modules;

import redis.clients.jedis.Jedis;

/**
 * Hyperloglog基数统计
 *
 * @author YunGang.Guo
 * @date 2022/03/24 14:33
 **/
public class Hyperloglog {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("127.0.0.1", 6379);
        System.out.println(jedis.ping());

        //创建一组数据  命令pfadd
        //不含有重复元素
        jedis.pfadd("myNum1", "a", "b", "c", "d", "e", "f", "g");
        jedis.pfadd("myNum2", "f", "g", "h", "i", "j", "k", "l", "m");
        //含有重复元素n
        jedis.pfadd("myNum3", "n", "o", "p", "q", "n");

        //统计数据集的基数数量 命令pfcount
        long myNum1 = jedis.pfcount("myNum1");
        System.out.println(myNum1);
        long myNum2 = jedis.pfcount("myNum2");
        System.out.println(myNum2);
        long myNum3 = jedis.pfcount("myNum3");
        System.out.println(myNum3);

        //合并数据集 命令pfmerge
        jedis.pfmerge("myNum4","myNum1","myNum2");
        long myNum4 = jedis.pfcount("myNum4");
        System.out.println(myNum4);

    }
}
